<template>
	<div class="app-container">
    <el-form :inline="true" :model="dataForm" @submit.native.prevent @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input placeholder="计划编号" v-model="dataForm.planId" :clearable="true" size="mini">
          <template slot="prepend">计划编号</template>
        </el-input>
      </el-form-item>

      <el-form-item>
        <el-input placeholder="品名" v-model="dataForm.productName" :clearable="true" size="mini">
          <template slot="prepend">品名</template>
        </el-input>
      </el-form-item>

      <el-form-item>
        <el-input placeholder="编码" v-model="dataForm.productGmp" :clearable="true" size="mini">
          <template slot="prepend">编码</template>
        </el-input>
      </el-form-item>

      <el-form-item>
        <el-input placeholder="批号" v-model="dataForm.batchNum" :clearable="true" size="mini">
          <template slot="prepend">批号</template>
        </el-input>
      </el-form-item>

      <el-form-item>
        <el-date-picker
          v-model="dataForm.nextTimePoint"
          type="daterange"
          @change="setTime"
          :clearable="true"
          range-separator="-"
          start-placeholder="下次请验开始时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          end-placeholder="下次请验结束时间"
          size="mini"
          :picker-options="pickerOptions"
          >
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-select v-model="dataForm.status" clearable placeholder="全部状态" size="mini">
          <el-option label="待完善" value="0" />
          <el-option label="未完成" value="1" />
          <el-option label="已完成" value="2" />
      	</el-select>
      </el-form-item>

      <el-form-item>
        <el-select v-model="dataForm.stabilityModeId" clearable placeholder="考察方式" size="mini">
          <el-option label="加速" value="1" />
          <el-option label="长期" value="2" />
      	</el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" class="pan-btn primary-btn" @click="searchData" icon="el-icon-search" size="mini">搜索</el-button>
      </el-form-item>

      <el-form-item>
        <el-button type="danger" class="pan-btn danger-btn" v-if="isAuth('stability:plan:delete')" @click="deleteData()" icon="el-icon-shopping-bag-2" :disabled="selectionList.length == 0" size="mini">删除</el-button>
      </el-form-item>

     <el-form-item>
        <el-button type="info" class="pan-btn info-btn" @click="importData" icon="el-icon-upload" size="mini">手工导入</el-button>
      </el-form-item>
    </el-form>

    <el-table
    	:data="dataList"
    	v-loading="dataListLoading"
      @selection-change="selectionChange"
      ref="dataTable"
    	border
      fit
      highlight-current-row
      style="width: 100%">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="planId"
        header-align="center"
        align="center"
        label="编号"
        width="70">
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        label="状态"
        width="100">
        <template slot-scope="{row}">
          <el-tag :type="row.status == 2 ? 'success' : row.status == 1 ? 'primary' : 'danger'" size="small">
            {{ row.status | statusFilter }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="stabilityModeName"
        header-align="center"
        align="center"
        label="方式"
        width="70">
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        label="进度"
        width="100">
        <template slot-scope="{row}">
          <el-progress type="circle" :percentage="mathPercentage(row.now, row.total)" size="mini" width="50" :color="makeColor(row.now, row.total)"></el-progress>
          <span>{{row.now}}/{{row.total}}</span>
        </template>
      </el-table-column>

      <el-table-column
        header-align="center"
        align="center"
        label="货品名称"
        width="220">
        <template slot-scope="{row}">
          <el-button type="text" @click="showTestBook(row)">{{ row.productName }}</el-button>
        </template>
      </el-table-column>
      <el-table-column
        prop="productGmp"
        header-align="center"
        align="center"
        label="物料编码"
        width="100">
      </el-table-column>
      <el-table-column
        prop="productSpec"
        header-align="center"
        align="center"
        label="规格">
        <template slot-scope="{row}">
          <span v-html="row.productSpec"></span>
        </template>
      </el-table-column>
      <el-table-column
        prop="batchNum"
        header-align="center"
        align="center"
        label="批号"
        width="90">
      </el-table-column>
      <el-table-column
        prop="inventory"
        header-align="center"
        align="center"
        label="入库量">
        <template slot-scope="{row}">
          <span>{{ row.incomingMini + row.incomingMiniUnitName + '/' + row.incomingBig + row.incomingBigUnitName }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="inventory"
        header-align="center"
        align="center"
        label="库存量"
        width="70">
        <template slot-scope="{row}">
          <span v-if="row.inventory == null" style="color: red;">未知</span>
          <el-button v-else type="text" size="small" @click="showBook(row)">{{ row.inventory + row.inventoryUnitName }}</el-button>
        </template>
      </el-table-column>
      <el-table-column
        prop="validityDate"
        header-align="center"
        align="center"
        label="存样日期"
        width="100">
        <template slot-scope="{row}">
          {{ row.storeDate | changeTime }}
        </template>
      </el-table-column>
      <el-table-column
        prop="validityDate"
        header-align="center"
        align="center"
        label="有效期至"
        width="100">
        <template slot-scope="{row}">
          {{ row.validityDate | changeTime }}
        </template>
      </el-table-column>
      <el-table-column
        prop="envT"
        header-align="center"
        align="center"
        label="温度"
        width="70">
      </el-table-column>
      <el-table-column
        prop="nextTimePoint"
        header-align="center"
        align="center"
        label="下次请验时间"
        width="120">
        <template slot-scope="{row}">
          {{ row.nextTimePoint == null ? '' : row.nextTimePoint.split(' ')[0] }}
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        label="操作"
        width="220">
        <template slot-scope="scope">
          <el-button type="info" class="pan-btn info-btn" @click="info(scope.row)" size="mini">查看</el-button>
          <el-button type="warning" class="pan-btn warning-btn" size="mini" @click="update(scope.row)" v-if="isAuth('stability:plan:update')">修改</el-button>
          <el-button type="danger" class="pan-btn danger-btn" size="mini" @click="scope.row.status = 0" v-if="isAuth('stability:plan:regist') && scope.row.status == 2">解锁</el-button>
          <el-button type="success" class="pan-btn success-btn" size="mini" @click="regist(scope.row)" v-if="isAuth('stability:plan:regist') && scope.row.status == 1 && scope.row.stabilityModeId != null">发起</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>

    <plan-info
      v-if="infoVisible"
      @close="close('infoVisible')"
      :childDataForm="childDataForm" />

    <get-select
      v-if="selectVisible"
      @close="close('selectVisible')"
      @refreshData="getDataList"
      :childDataForm="childDataForm" />

    <get
      v-if="getVisible"
      @close="close('getVisible')"
      @submit="getDataList"
      :childDataForm="childDataForm" />

    <book
      v-if="bookVisible"
      @close="close('bookVisible')"
      @reflushData="getDataList"
      :childDataForm="childDataForm" />

    <product-select
      @getProduct="getProduct"
      @showProductSelect="close('productSelectVisible')"
      :childDataForm="childDataForm"
      v-if="productSelectVisible" />

    <standard-select
      v-if="standardSelectVisible"
      @closeInner="close"
      @getStandard="getStandard"
      :childDataForm="childDataForm" />

    <plan-test-book
      v-if="testBookVisible"
      @close="close('testBookVisible')"
      :childDataForm="childDataForm" />

    <plan-import
      v-if="importVisible"
      @close="close('importVisible')"
      @submit="getDataList" />

    <select-version
      v-if="selectVersionVisible"
      @close="close('selectVersionVisible')"
      @getSelectVersion="getSelectVersion"
      :childDataForm="childDataForm" />

    <el-dialog
      title="配置初始数量"
      :visible.sync="inventoryVisible"
      :before-close="closeInventoryInput"
      :append-to-body="true"
      :close-on-click-modal="false"
      width="40%">
      <el-form>
        <el-card>
          {{ "入库数量(小单位): " + waitRow.incomingMini }}<span style="color: red">{{ waitRow.incomingMiniUnitName }}</span>
        </el-card>
        <el-card>
          {{ "入库数量(大单位): " + waitRow.incomingBig + waitRow.incomingBigUnitName }}
        </el-card>
        <el-form-item label="入库数量(小单位):">
          <el-input v-model="waitRow.incomingMini" @change="setWaitRowInventory('incomingMini')" placeholder="小单位入库(数值)">
            <el-select @change="setWaitRowInventoryUnit('incomingMiniUnit')" value-key="unitId" v-model="waitRow.incomingMiniUnit" slot="append" placeholder="单位" style="width: 100px;">
              <el-option v-for="(item,itemIndex) in unitList" :key="itemIndex" :label="item.unitName" :value="item" />
            </el-select>
          </el-input>
        </el-form-item>
        <el-form-item label="入库数量(大单位):">
          <el-input v-model="waitRow.incomingBig" @change="setWaitRowInventory('incomingBig')" placeholder="大单位入库(数值)">
            <el-select @change="setWaitRowInventoryUnit('incomingBigUnit')" value-key="unitId" v-model="waitRow.incomingBigUnit" slot="append" placeholder="单位" style="width: 100px;">
              <el-option v-for="(item,itemIndex) in unitList" :key="itemIndex" :label="item.unitName" :value="item" />
            </el-select>
          </el-input>
        </el-form-item>
        <el-form-item label="批号:">
          <el-input v-model="waitRow.batchNum" @change="setPlanName" placeholder="批号"></el-input>
        </el-form-item>
        <el-form-item label="库存量:">
          <el-input v-model="waitRow.inventory" @change="setWaitRowInventory('inventory')" placeholder="库存量(数值)">
            <el-select @change="setWaitRowInventoryUnit('inventoryUnit')" value-key="unitId" v-model="waitRow.inventoryUnit" slot="append" placeholder="单位" style="width: 100px;">
              <el-option v-for="(item,itemIndex) in unitList" :key="itemIndex" :label="item.unitName" :value="item" />
            </el-select>
          </el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="close('inventoryVisible')">取 消</el-button>
        <el-button type="primary" class="pan-btn primary-btn" @click="inputInventoryOk">确 定</el-button>
      </span>
    </el-dialog>

	</div>
</template>

<script>
  import CommonMethod from '@/views/mixin/common'
  import { CODE_OK } from '@/common/js/config'
  import { isPositiveNumber } from '@/common/js/validate'
  import { isBlank } from '@/common/js/utils'
  import { getUnitList,getVersion } from '@/api/check'
  import {
    stabilityPlanList,
    getTimeAndItemForPlan,
    getStandardAndItems,
    getInventoryBookByPlanId,
    deletePlan
  } from '@/api/stability'
  import PlanInfo from './plan-info'
  import GetSelect from './get-select'
  import Get from './get'
  import Book from './plan-book'
  import ProductSelect from '@/views/modules/base/product-select'
  import StandardSelect from '@/views/modules/base/standard-select'
  import PlanTestBook from './plan-test-book'
  import PlanImport from './plan-import'
  import SelectVersion from '@/views/modules/common/select-version'
	export default {
    name: 'wenkaoshi',
    filters: {
      statusFilter(status) {
        const statusMap = {
          0: '待完善',
          1: '未完成',
          2: '已完成'
        }
        return statusMap[status]
      }
    },
    mixins: [CommonMethod],
		data(){
      return{
        pickerOptions:{shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          },
          {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }
          ]},
        infoVisible: false,
        getVisible: false,
        bookVisible: false,
        testBookVisible: false,
        importVisible: false,
        selectVersionVisible: false,
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataForm: {
          status: '1',
          stabilityModeId: null,
          nextTimePointStart: null,
          nextTimePointEnd: null,
          planId: null
        },
        childDataForm: '',
        waitRow: {},
        needForm: {
          selectProduct: false,
          inputInventory: false
        },
        productSelectVisible: false,
        standardSelectVisible: false,
        inventoryVisible: false,
        selectVisible: false,
        unitList: [],
        selectionList: []
      }
		},
    mounted() {
      this.getInfo()
    },
    components: {
    	PlanInfo,Get,Book,ProductSelect,StandardSelect,GetSelect,PlanTestBook,PlanImport,SelectVersion
    },
		methods:{
      makeColor(a,b){
        let complete = (a/b).toFixed(2)*100;
        if(complete == 100){
          return 'LightGreen'
        }else{
          return 'DeepSkyBlue'
        }
      },
      mathPercentage(a,b){
        return (a/b).toFixed(2)*100
      },
      getLocalTime(date) {
       return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+" 00:00:00";
      },
      getSelectVersion(v) {
        this.$router.push({
        	name: this.getPrintCheckName('稳定性考察', v.versionNum),
          params: this.waitRow
        })
      },
      importData() {
        this.importVisible = true
      },
      showTestBook(row) {
        this.childDataForm = row
        this.testBookVisible = true
      },
      deleteData(id) {
      	if (this.selectionList.length == 0 && id == undefined) {
      		this.$message.error('请选择至少一条员工信息')
      		return
      	}
      	let ids = id ? [id] : this.selectionList.map(item => {
      		return item.planId
      	})
      	let msg = id ? '此操作将永久删除此稳考计划信息, 是否继续?' : '此操作将永久删除选中的稳考计划信息, 是否继续?'
      	this.$confirm(msg, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
       	}).then(() => {
       		deletePlan(ids).then(res => {
       			if (res.code === CODE_OK) {
       				this.$message({
                type: 'success',
                message: '删除成功!'
              })
       				this.getDataList()
       			}else{
       				this.$message.error(res.msg)
       			}
       		})
        }).catch(() => {})
      },
      selectionChange(obj) {
        this.selectionList = obj
      },
      setPlanName() {
        if (isBlank(this.waitRow.batchNum)) {
          this.$message.error('批号不能为空')
          return
        }
        this.waitRow.planName = this.waitRow.productName + '(' + this.waitRow.batchNum + ')' + '【' + this.waitRow.stabilityModeName + '】'
      },
      showBook(row) {
        const params = {
          planId: row.planId
        }
        getInventoryBookByPlanId(params).then(res => {
          if (res.code === CODE_OK) {
            this.childDataForm = {
              plan: JSON.parse(JSON.stringify(row)),
              books: res.list
            }
            this.bookVisible = true
          }else{
            this.$message.error(res.msg)
          }
        })
      },
      regist(row1) {
        let row = JSON.parse(JSON.stringify(row1))
        if (row.status == 0) {
            this.$message.error("请先修改计划")
            return
        }
        if (row.projectId == null) {
          this.$message.error("未绑定稳考方案，请联系管理员")
          return
        }
        const params = {
          planId: row.planId
        }
        getTimeAndItemForPlan(params).then(res => {
          if (res.code === CODE_OK) {
            row.times = res.times
            if (res.nextTime.getQuantity == null || res.nextTime.getQuantity == '') {
              this.$message.error('此月份未制定计划，若不是检验此月份的，请上锁，否则请先修改')
              return
            }
            row.nextTime = res.nextTime
            this.$set(params,'timeId',res.nextTime.planTimeId)
            this.$set(params,'isBase',0)
            this.$set(params,'isOne',0)
            getStandardAndItems(params).then(res => {
              if (res.code === CODE_OK) {
                let standard = res.info.standards
                if (isBlank(standard)) {
                  this.$message.error('未绑定检验标准,请绑定')
                  return
                }
                let items = row.nextTime.bitmes
                let allItems = []
                if (standard.length == 1) {
                  standard = standard[0]
                  allItems = standard.items
                }else{
                  let insideInspectionStandardNum = []
                  let accordingToInside = []
                  let nationInspectionStandardNum = []
                  let accordingToNation = []
                  for (let i=0,j=standard.length; i<j; i++) {
                    let s = standard[i]
                    if (!isBlank(s.insideInspectionStandardNum)) {
                      insideInspectionStandardNum.push(s.insideInspectionStandardNum)
                    }
                    if (!isBlank(s.accordingToInside)) {
                      accordingToInside.push(s.accordingToInside)
                    }
                    if (!isBlank(s.nationInspectionStandardNum)) {
                      nationInspectionStandardNum.push(s.nationInspectionStandardNum)
                    }
                    if (!isBlank(s.accordingToNation)) {
                      accordingToNation.push(s.accordingToNation)
                    }
                    allItems = allItems.concat(s.items)
                  }
                  if (insideInspectionStandardNum.length != 0) {
                    insideInspectionStandardNum = insideInspectionStandardNum.join('、')
                  }else{
                    insideInspectionStandardNum = ''
                  }
                  if (accordingToInside.length != 0) {
                    accordingToInside = accordingToInside.join('、')
                  }else{
                    accordingToInside = ''
                  }
                  if (nationInspectionStandardNum.length != 0) {
                    nationInspectionStandardNum = nationInspectionStandardNum.join('、')
                  }else{
                    nationInspectionStandardNum = ''
                  }
                  if (accordingToNation.length != 0) {
                    accordingToNation = accordingToNation.join('、')
                  }else{
                    accordingToNation = ''
                  }
                  standard = {
                    insideInspectionStandardNum: insideInspectionStandardNum,
                    accordingToInside: accordingToInside,
                    nationInspectionStandardNum: nationInspectionStandardNum,
                    accordingToNation: accordingToNation
                  }
                }
                this.$set(row,'isAllTest',items.length == allItems.length ? 0 : 1)
                this.$set(row, 'standard', standard)
                this.$set(row, 'allItems', allItems)
                this.$set(row, 'itemNames', row.isAllTest == 0 ? '全检' : items.map(i => {
                  return i.inspectionItemName
                }).join('、'))
                this.waitRow = JSON.parse(JSON.stringify(row))
                const params1 = {
                  checkTypeId: 6,
                  printClassify: '请验单'
                }
                getVersion(params1).then(res => {
                  if (res.code === CODE_OK) {
                    this.getSelectVersion(res.list.find(v => v.isCurrent == 0))
                  }else{
                    this.$message.error(res.msg)
                  }
                })
              }else{
                this.$message.error(res.msg)
              }
            })
          }else{
            this.$message.error(res.msg)
          }
        })
      },
      update(row) {
        const params = {
          planId: row.planId
        }
        //只计划
        if (row.stabilityModeId == null) {
          this.childDataForm = {
            oldPlanId: row.planId,
            groupGetQuantity: row.inventory,
            groupGetUnitId: row.inventoryUnitId,
            groupGetUnitName: row.inventoryUnitName,
            productName: row.productName,
            batchNum: row.batchNum,
            checkId: row.checkId,
            productId: row.productId,
            productGmp: row.productGmp,
            productSpec: row.productSpec,
            productPackSpec: row.productPackSpec,
            onlyPlan: true,
            incomingBig: row.incomingBig,
            incomingBigUnitId: row.incomingBigUnitId,
            incomingBigUnitName: row.incomingBigUnitName,
            storeDate: row.storeDate
          }
          this.selectVisible = !this.selectVisible
          return
        }
        //已领取和编写计划，只修改
        getTimeAndItemForPlan(params).then(res => {
          if (res.code === CODE_OK) {
            row.times = res.times
            //完善计划
            if (row.status == 0) {
              this.waitRow = JSON.parse(JSON.stringify(row))
              //判断是否需要选择货品
              this.needForm.selectProduct = isBlank(row.productId)
              //判断是否需要输入库存量
              this.needForm.inputInventory = true
              this.flushView()
            }else{
              //修改计划
              this.$set(params,'isBase',0)
              getStandardAndItems(params).then(res => {
                if (res.code === CODE_OK) {
                  //用于后面修改项目时的allItems和baseStandard
                  this.$set(row, 'standards', res.info.standards)
                  this.waitRow = JSON.parse(JSON.stringify(row))
                  this.showGet()
                }else{
                  this.$message.error(res.msg)
                }
              })
            }
          }else{
            this.$message.error(res.msg)
          }
        })
      },
      flushView() {
        if (this.needForm.selectProduct) {
          this.showProductSelect()
        }else{
          this.showInventoryInput()
        }
      },
      showProductSelect() {
        this.childDataForm = {
          isMultiple: false,
          isStability: true,
          productName: this.waitRow.productName
        }
        this.productSelectVisible = true
      },
      getProduct(p) {
        this.waitRow.productId = p.productId
        this.waitRow.productGmp = p.productGmp
        this.waitRow.productName = p.productName
        this.waitRow.productSpec = p.productSpec
        this.productSelectVisible = false
        this.needForm.selectProduct = false
        this.$nextTick(() => {
          this.flushView()
        })
      },
      showStandardSelect() {
        this.childDataForm = {
          accordingToInside: this.waitRow.productName
        }
        this.standardSelectVisible = true
      },
      getStandard(s) {
        this.waitRow.standard = s
        this.waitRow.allItems = s.items
        this.standardSelectVisible = false
        this.$nextTick(() => {
          this.flushView()
        })
      },
      showInventoryInput() {
        getUnitList().then(res => {
          if (res.code === CODE_OK) {
            this.unitList = res.list
            //incomingMini
            this.$set(this.waitRow, 'incomingMiniUnit', {
              unitId: this.waitRow.incomingMiniUnitId,
              unitName: this.waitRow.incomingMiniUnitName,
            })
            //incomingBig
            this.$set(this.waitRow, 'incomingBigUnit', {
              unitId: this.waitRow.incomingBigUnitId,
              unitName: this.waitRow.incomingBigUnitName,
            })
            //inventory
            this.waitRow.inventoryUnitId = JSON.parse(JSON.stringify(this.waitRow.incomingMiniUnitId))
            this.waitRow.inventoryUnitName = JSON.parse(JSON.stringify(this.waitRow.incomingMiniUnitName))
            this.$set(this.waitRow, 'inventoryUnit', {
              unitId: this.waitRow.inventoryUnitId,
              unitName: this.waitRow.inventoryUnitName,
            })
            this.inventoryVisible = true
          }else{
            this.$message.error(res.msg)
          }
        })
      },
      closeInventoryInput() {
        this.inventoryVisible = false
        this.needForm.inputInventory = false
      },
      setWaitRowInventory(prop) {
        if (!isPositiveNumber(this.waitRow[prop])) {
          this.$message.error('请输入正数值类型')
          this.waitRow[prop] = null
        }
      },
      setWaitRowInventoryUnit(prop) {
        let unitId = prop + 'Id'
        let unitName = prop + 'Name'
        this.waitRow[unitId] = this.waitRow[prop].unitId
        this.waitRow[unitName] = this.waitRow[prop].unitName
        if (prop == 'inventoryUnit') {
          this.waitRow.incomingMiniUnitId = JSON.parse(JSON.stringify(this.waitRow[unitId]))
          this.waitRow.incomingMiniUnitName = JSON.parse(JSON.stringify(this.waitRow[unitName]))
          this.$set(this.waitRow, 'incomingMiniUnit', {
            unitId: this.waitRow.incomingMiniUnitId,
            unitName: this.waitRow.incomingMiniUnitName,
          })
        }else if(prop == 'incomingMiniUnit') {
          this.waitRow.inventoryUnitId = JSON.parse(JSON.stringify(this.waitRow[unitId]))
          this.waitRow.inventoryUnitName = JSON.parse(JSON.stringify(this.waitRow[unitName]))
          this.$set(this.waitRow, 'inventoryUnit', {
            unitId: this.waitRow.inventoryUnitId,
            unitName: this.waitRow.inventoryUnitName,
          })
        }
      },
      inputInventoryOk() {
        if (isBlank(this.waitRow.batchNum)) {
          this.$message.error('批号不能为空')
          return
        }
        if (isBlank(this.waitRow.inventory)) {
          this.$message.error('库存量不能为空')
          return
        }
        if (this.waitRow.inventory * 1 > this.waitRow.incomingMini * 1) {
          this.$message.error('当前库存量必须小于等于入库量(小)')
          return
        }
        this.closeInventoryInput()
        this.showGet()
      },
      showGet() {
        this.childDataForm = {
          projects: [JSON.parse(JSON.stringify(this.waitRow))]
        }
        this.getVisible = true
      },
      info(row) {
        const params = {
          planId: row.planId
        }
        getTimeAndItemForPlan(params).then(res => {
          if (res.code === CODE_OK) {
            row.times = res.times
            this.childDataForm = JSON.parse(JSON.stringify(row))
            this.infoVisible = true
          }else{
            this.$message.error(res.msg)
          }
        })
      },
      searchData() {
      	this.pageIndex=1
      	this.getDataList()
      },
      getInfo() {
        this.getDataList()
      },
      getDataList() {
      	this.dataListLoading = true
        const params = {
          page: this.pageIndex,
          limit: this.pageSize,
          productName: this.dataForm.productName || null,
          productGmp: this.dataForm.productGmp || null,
          batchNum: this.dataForm.batchNum || null,
          status: this.dataForm.status || null,
          stabilityModeId: this.dataForm.stabilityModeId || null,
          nextTimePointStart: this.dataForm.nextTimePointStart || null,
          nextTimePointEnd: this.dataForm.nextTimePointEnd || null,
          planId: this.dataForm.planId || null
        }
        stabilityPlanList(params).then(res => {
        	if (res.code === CODE_OK) {
        		this.dataList = res.page.list
        		this.totalPage = res.page.totalCount
        	}else{
        		this.$message.error(res.msg)
        	}
        	this.dataListLoading = false
        }).catch(() => {})
      },
      close(val) {
        this.childDataForm = ''
        this[val] = false
      },
      setTime() {
        if (!isBlank(this.dataForm.nextTimePoint)) {
          this.dataForm.nextTimePointStart = this.dataForm.nextTimePoint[0]
          this.dataForm.nextTimePointEnd = this.dataForm.nextTimePoint[1]
        }else{
          this.dataForm.nextTimePointStart = null
          this.dataForm.nextTimePointEnd = null
        }
      }
		},
    watch: {
      $route: {
        handler: function (to, from){
          if (to.name === '稳考室') {
            if (!isBlank(to.params.id)) {
              this.dataForm.planId = to.params.id
            }
            this.getDataList()
          }
        },
        immediate: true
      }
    }
	}
</script>

<style scoped>
  >>> .el-form-item__content {
    line-height: normal;
  }
</style>
